<?php
class StudentsController extends AppController {
	var $name = 'Students';

	function index() {
		$this->pageTitle = 'Список студентов';
                $this->set('students', $this->Student->find('all'));
	}

	function view($id) {
		$this->Student->id = $id;
		$this->set('student', $this->Student->read());

	}

	function add() {
		if (!empty($this->data)) {
			if ($this->Student->save($this->data)) {
				$this->Session->setFlash('New Student has been saved.');
				$this->redirect(array('action' => 'index'));
			}
		}
	}
        
        function delete($id) {
	        $this->Student->delete($id);
	        $this->Session->setFlash('Student with id: '.$id.' has been deleted.');
	        $this->redirect(array('action'=>'index'));
        }
        
        function edit($id = null) {
	        $this->Student->id = $id;
	        if (empty($this->data)) {
		        $this->data = $this->Student->read();
	        } else {
		        if ($this->Student->save($this->data)) {
			        $this->Session->setFlash('Informaton about Student has been updated.');
			        $this->redirect(array('action' => 'index'));
		}
	        }
        }
}
?>